package com.imooc.follow.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.imooc.commons.model.pojo.Follow;

/**
 * \* @author: bear
 * \* Date: 2021-08-04-10:26
 * \* describe: 关注，取关 mapper
 */
public interface FollowMapper {

	//查询关键信息
	@Select("select id, diner_id, follow_diner_id, is_valid from t_follow"
			+ " where diner_id = #{dinerId} and follow_diner_id = #{followDinerId}")
	Follow selectFollow(@Param("dinerId") Integer dinerId,@Param("followDinerId") Integer followDinerId);

	//添加关注信息
	@Insert("insert into t_follow (diner_id, follow_diner_id, is_valid, create_date, update_date)"
			+ " values (#{dinerId},#{followDinerId},1,now(),now())")
	int save(@Param("dinerId")Integer dinerId,@Param("followDinerId") Integer followDinerId);

	//修改关注信息
	@Update("update t_follow set is_valid=#{isFollowed} and update_date= now() where id=#{id}")
	int update(@Param("id")Integer id,@Param("isFollowed") int isFollowed);
}
